﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Medical_Store_Billing.Data_Access_Layer;
using Medical_Store_Billing.Object_Class;
using System.Windows.Forms;

namespace Medical_Store_Billing.Business_Login_Layer
{
    class XuathangBLL
    {
        XuathangDAL m_xuathangdal = new XuathangDAL();
        chitietxuathangclass m_chitiet;
        Xuathangclass m_xh;

        public bool Kiemtrakho(String mahang, int sl)
        {
            DataTable tb = m_xuathangdal.Kiemtrakho(mahang);

            int result = Int32.Parse(tb.Rows[0][0].ToString());
            
            
            if (result >= sl)
                return true;
            else return false;
        }
        public int Demxuathang()
        {
           
           return Int32.Parse(m_xuathangdal.Demxuathang().Rows[0][1].ToString());
        }
        public bool Themxuathang(String mapx, String ngay, String makh, String ghichu, String manv, String madathang)
        {
            try
            {
                m_xh = new Xuathangclass();

                m_xh.mapx = mapx;
                m_xh.ngay = Convert.ToDateTime(ngay);
                m_xh.makh = makh;
                m_xh.manv = manv;
                m_xh.ghichu = ghichu;
                m_xh.madathang = madathang;

                return m_xuathangdal.Themxuathang(m_xh);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }
        public DataTable laydsxh()
        {
            return m_xuathangdal.Laydsxuathang();
        }

        public bool Themchitietxuathang(String mapx, String mahang, int soluong, float dongia)
        {
            try
            {
                m_chitiet = new chitietxuathangclass();

                m_chitiet.mapx = mapx;
                m_chitiet.mahang = mahang;
                m_chitiet.soluong = soluong;
                m_chitiet.dongia = dongia;

                return m_xuathangdal.Themchitietxuathang(m_chitiet);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }
        public DataTable Timxuathang(String name)
        {
            return m_xuathangdal.Timxuathang(name);
        }
        public DataTable Laychitietxuat(String mapx)
        {
            return m_xuathangdal.Laychitietxuat(mapx);
        }
        public DataTable Laychitietxuat1(String mapx)
        {
            return m_xuathangdal.Laychitietxuat1(mapx);
        }
    }
}
